#include "Camera.h"

void FpsCamera::render()
{
    using namespace glm;
    direction = normalize(vec3(cos(radians(pitch)) * cos(radians(yaw)),
                               sin(radians(pitch)),
                               cos(radians(pitch)) * sin(radians(yaw))));
    Object3D::viewProjectionMatrix =
        projectionMatrix *
        glm::lookAt(position, position + direction, {0.f, 1.f, 0.f});
}

void FpsCamera::processInput(double dx, double dy)
{
    static bool firstMouse = true;
    const double sensitivity = 50.0;
    if (firstMouse)
    {
        firstMouse = false;
        return;
    }

    yaw += dx * sensitivity;
    pitch += dy * sensitivity;
    if (pitch > 85.f)
    {
        pitch = 85.f;
    }
    else if (pitch < -85.f)
    {
        pitch = -85.f;
    }
}